package me.zhengjie.modules.file.service.dto;

import lombok.Data;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: Firework
 * @Description:
 * @Date Created in 11:232021/4/7
 * @Modidied By:
 */
@Data
public class FilePublicModel {
    private Integer id;
    private String userName;
    /** 创建时间 */
    private Timestamp createTime;
    /** 文件名 */
    private String fileName;
    /** 文件地址 */
    private String filePath;
    private String type;
    private String size;
    private String realName;

    public FilePublicModel(Integer id, String userName, String fileName,
                           String filePath, String type, String size,String realName,Object createTime) {
        this.id = id;
        this.userName = userName;
        this.createTime = stringToTimestamp(createTime.toString());
        this.fileName = fileName;
        this.filePath = filePath;
        this.type=type;
        this.size=size;
        this.realName=realName;
    }

    public static Timestamp stringToTimestamp(String dateStr){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        try {
            Date date = sdf.parse(dateStr);
            date.getTime();
            cal.setTime(date);
            return new Timestamp(cal.getTimeInMillis());
        } catch (ParseException e) {
            e.printStackTrace();
        }

        cal.setTime(new Date());
        return new Timestamp(cal.getTimeInMillis());
    }
}
